import json

from Config.Config import get_redis_client


# 从蓝图转载到Main函数中
def retrieve_params_from_redis():
    # 使用存储参数时使用的相同键名来获取数据
    key = "regressionShare"

    # 从Redis获取JSON格式的数据
    redis_client = get_redis_client()
    json_data = redis_client.get(key)
    if json_data:
        json_data = json_data.decode('utf-8')
    print(json_data)

    if json_data is not None:
        # 将JSON字符串反序列化为Python字典
        params_dict = json.loads(json_data)

        # 现在可以从字典中提取所需参数
        featureColumns = params_dict['featureColumns']
        featureColumn = params_dict['featureColumn']
        test_size_user = params_dict['test_size_user']
        random_state_user = params_dict['random_state_user']
        train_key = params_dict['train_file']
        test_key = params_dict['test_file']

        return featureColumns, featureColumn, test_size_user, random_state_user, train_key, test_key
    else:
        print("没有在Redis中找到对应的参数")
        # 根据需要返回默认值或者抛出异常
        return "redis中无参数"
